package com.example.demo.domain;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.util.FileUtil;
import com.example.demo.util.JsonUtil;

import java.util.List;

//@Service
//@Transactional
public class QueryConfig {

//    @Autowired
//    private QueryDao queryDao;

    private static String basePath = FileUtil.projectPath;

    private static String sepa = FileUtil.getSystemSeparator();

    private String sql;
    private String sqltotalcount;

    public String getSqltotalcount() {
        return sqltotalcount;
    }

    public void setSqltotalcount(String sqltotalcount) {
        this.sqltotalcount = sqltotalcount;
    }

    private List<Condition> conditions;

    private List<TableField> tableFields;

    public String getSql() {
        return sql;
    }

    public void setSql(String sql) {
        this.sql = sql;
    }

    public List<Condition> getConditions() {
//        for (Condition c: this.conditions) {
//            try{
//                if (c.getSql() != "" && c.getSql() != null) {
//                    List<Map> list = queryDao.executeSql(c.getSql());
//                    List<CombItem> combItems = new ArrayList<>();
//                    for (Map m: list) {
//                        combItems.add(JsonUtil.mapToObject(m, CombItem.class));
//                    }
//                    c.setInit(combItems);
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//
//        }
        return conditions;
    }

    public void setConditions(List<Condition> conditions) {
        this.conditions = conditions;
    }

    public List<TableField> getTableFields() {
        return tableFields;
    }

    public void setTableFields(List<TableField> tableFields) {
        this.tableFields = tableFields;
    }

//    public QueryConfig(String projectName, String queryName) {
//        String path = basePath + sepa + "query_config" + sepa + projectName + sepa +
//                queryName + sepa + "query.json";
//        String jsonStr = JsonUtil.readFromFile(path);
//        JSONObject object = JSON.parseObject(jsonStr);
//        this.sql = object.getString("sql");
//        this.conditions = object.getObject("conditions", List.class);
//        this.tableFields = object.getObject("tableFields", List.class);
//    }
}
